package com.itcast.rabbitmq.utils;


import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName ConnectionUtil
 * @Description rabbitUtils
 * @Author Trigger Wu
 * @Date 2018/9/2713:55
 * @Version 1.0
 **/

public class ConnectionUtil {
    public static Connection getConnection() throws IOException, TimeoutException {
        //定义连接工厂
        ConnectionFactory factory= new ConnectionFactory();
        //设置服务地址
        factory.setHost("192.168.53.86");
        //端口
        factory.setPort(5672);
        //设置账号信息
        factory.setUsername("root");
        factory.setPassword("123456");
        factory.setVirtualHost("/");
        //通过工程获取链接
        Connection connection = factory.newConnection();
        return connection;
    }
}
